<template>
  <div class="my">
    <div class="top">
      <div class="top1">
        <div class="left">
          <div class="name">{{ userInfo.nickname }}</div>
          <div class="intro">{{ userInfo.intro }}</div>
        </div>
        <img
          class="right"
          v-if="userInfo.avatar"
          :src="baseUrl + userInfo.avatar"
          alt=""
          @click="goInfo"
        />
        <img
          class="right"
          v-else
          src="@/assets/logo.png"
          alt=""
          @click="goInfo"
        />
      </div>
      <ul class="top2">
        <li class="top2-item">
          <div class="num">{{ userInfo.submitNum }}</div>
          <div class="txt">累计答题</div>
        </li>
        <li class="top2-item">
          <div class="num">{{ userInfo.collectArticles.length }}</div>
          <div class="txt">收藏题目</div>
        </li>
        <li class="top2-item">
          <div class="num">{{ userInfo.errorNum }}</div>
          <div class="txt">我的错题</div>
        </li>
        <li class="top2-item">
          <div class="num">{{ accuracy }}%</div>
          <div class="txt">正确率</div>
        </li>
      </ul>
      <div class="top3">
        <myCell
          class="cell"
          icon="&#xe64d;"
          title="我的岗位"
          :value="userInfo.position"
        ></myCell>
      </div>
    </div>
    <div class="content">
      <div class="middle">
        <h3 class="middle-title">面经数据</h3>
        <ul class="middle-content">
          <li class="middle-item">
            <div class="m1">
              昨日阅读<span>+{{ userInfo.shareData.read.yesterday }}</span>
            </div>
            <div class="m2">{{ userInfo.shareData.read.total }}</div>
            <div class="m3">
              阅读总数
            </div>
          </li>
          <li class="middle-item">
            <div class="m1">
              昨日获赞<span>+{{ userInfo.shareData.star.yesterday }}</span>
            </div>
            <div class="m2">{{ userInfo.shareData.star.total }}</div>
            <div class="m3">
              获赞总数
            </div>
          </li>
          <li class="middle-item">
            <div class="m1">
              昨日新增<span>+{{ userInfo.shareData.comment.yesterday }}</span>
            </div>
            <div class="m2">{{ userInfo.shareData.comment.total }}</div>
            <div class="m3">
              评论总数
            </div>
          </li>
        </ul>
      </div>
      <div class="bottom">
        <myCell
          icon="&#xe655;"
          title="我的面经分享"
          :value="userInfo.history.share.length"
        ></myCell>
        <myCell icon="&#xe656;" title="我的消息" value="98"></myCell>
        <myCell
          icon="&#xe654;"
          title="收藏的题库"
          :value="userInfo.collectQuestions.length"
        ></myCell>
        <myCell
          icon="&#xe648;"
          title="收藏的企业"
          :value="userInfo.history.technic.length"
        ></myCell>
        <myCell
          icon="&#xe64f;"
          title="我的错题"
          :value="userInfo.errorQuestions.length"
        ></myCell>
        <myCell
          icon="&#xe611;"
          title="收藏的面试经验"
          :value="userInfo.collectArticles.length"
        ></myCell>
      </div>
    </div>
  </div>
</template>
<script>
// 导入  注册   使用
import myCell from './myCell'
import { mapState } from 'vuex'
// import { getLocal } from '@/utils/local.js'
// import { auInfo } from '@/api/my.js'
export default {
  components: {
    myCell
  },
  computed: {
    ...mapState(['userInfo'])
  },
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL,
      accuracy: (
        ((this.$store.state.userInfo.submitNum -
          this.$store.state.userInfo.errorNum) /
          this.$store.state.userInfo.submitNum) *
        100
      ).toFixed(0)
    }
  },
  methods: {
    goInfo () {
      this.$router.push('/home/myInfo')
    }
  },
  // created () {
  //   if (this.$store.state.isLogin) {
  //     return null
  //   } else {
  //     if (getLocal('token')) {
  //       auInfo().then(res => {
  //         this.$store.commit('setUserInfo', res.data.data)
  //         this.$store.commit('setIsLogin', true)
  //       })
  //     } else {
  //       this.$router.push('/login')
  //     }
  //   }
  // },
  mounted () {
    document.body.style.backgroundColor = '#f7f4f5'
  },
  beforeDestroy () {
    document.body.style.backgroundColor = '#fff'
  }
}
</script>
<style lang="less" scoped>
.my {
  .top {
    background-color: #c1002e;
    padding: 31px @15 55px;
    position: relative;
    .top1 {
      display: flex;
      justify-content: space-between;
      .name {
        font-size: 21px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        text-align: left;
        color: #ffffff;
        line-height: 30px;
        letter-spacing: 0px;
      }
      .intro {
        opacity: 0.7;
        font-size: 12px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: left;
        color: #ffffff;
        line-height: 16px;
        letter-spacing: 0px;
      }
      .right {
        width: 50px;
        height: 50px;
        border: 3px solid rgba(255, 255, 255, 0.38);
        border-radius: 50%;
      }
    }
    .top2 {
      display: flex;
      justify-content: space-between;
      text-align: center;
      padding-top: 31px;
      .top2-item {
        .num {
          font-size: 21px;
          font-family: DINAlternate, DINAlternate-Bold;
          font-weight: 700;
          text-align: center;
          color: #ffffff;
          line-height: 24px;
          letter-spacing: 0px;
        }
        .txt {
          padding-top: 6px;
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: center;
          color: #ffffff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
    }
    .top3 {
      position: absolute;
      bottom: -16px;
      left: 0;
      width: 100%;
      padding: 0 @15;
      .cell {
        border-radius: 8px;
      }
    }
  }
  .content {
    padding: 26px @15 0;
    .middle {
      border-radius: 8px;
      padding: 19px 15px;
      background-color: #fff;
      .middle-title {
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        text-align: left;
        color: #181a39;
        line-height: 20px;
        letter-spacing: 0px;
        padding-bottom: 17px;
      }
      .middle-content {
        display: flex;
        justify-content: space-between;
        .middle-item {
          text-align: center;
          .m1 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #b4b4bd;
            line-height: 14px;
            letter-spacing: 0px;
            span {
              color: #00b8d4;
            }
          }
          .m2 {
            font-size: 21px;
            font-family: DINAlternate, DINAlternate-Bold;
            font-weight: 700;
            text-align: center;
            color: #181a39;
            line-height: 24px;
            letter-spacing: 0px;
            padding: 10px 0 6px;
          }
          .m3 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #545671;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
      }
    }
    .bottom {
      margin: 10px 0 20px;
      background-color: #fff;
    }
  }
}
</style>
